
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib  uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<%@taglib   uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<script language="JavaScript">
    function checkAll(field)
    {
        if(document.form1.checkall.checked == true)
        {
            for (i = 0; i < field.length; i++)
            {field[i].checked = true ;
            }
            return true;
	
        }else{
            for (i = 0; i < field.length; i++)
            {field[i].checked = false ;
            }
            return false;
        }
     
    }
    function check()
    {

        document.form1.listF.checked==true;
    }

</script>

<script language="javascript">
    function show(){
        document.getElementById('frflightid').value ="";
        document.getElementById('frflightcode').value ="";
        document.getElementById('frflightdepar').value ="";
        document.getElementById('frflightdes').value ="";
        document.getElementById('frflightdate').value ="";
        document.getElementById('frflighttime').value ="";
        document.getElementById('frflightweb').value ="";
        document.getElementById('frflightemail').value ="";
        document.getElementById('frflightdess').value ="";
        document.getElementById('frflightid').disabled= true;
        document.fr.style.visibility='visible';
        document.getElementById('frinsert').style.visibility='visible';
        document.getElementById('frupdate').style.visibility='hidden';
        document.getElementById('frdelete').style.visibility='hidden';
    }


    function showedit1(element){

        document.fr.style.visibility='visible';
        document.getElementById('frinsert').style.visibility='hidden';
        document.getElementById('frupdate').style.visibility='visible';
        document.getElementById('frdelete').style.visibility='hidden';
        document.getElementById('frflightid').disabled= true;
        document.getElementById('frflightidd').value = document.getElementById('fr1flightid'+element).value;
        document.getElementById('frflightid').value = document.getElementById('fr1flightid'+element).value;
        document.getElementById('frflightcode').value = document.getElementById('fr1flightcode'+element).value;
        document.getElementById('frflightdepar').value = document.getElementById('fr1flightdepar'+element).value;
        document.getElementById('frflightdes').value = document.getElementById('fr1flightdes'+element).value;
        document.getElementById('frflightdate').value = document.getElementById('fr1flightdate'+element).value;
        document.getElementById('frflighttime').value = document.getElementById('fr1flighttime'+element).value;
        document.getElementById('frflightweb').value = document.getElementById('fr1flightweb'+element).value;
        document.getElementById('frflightemail').value = document.getElementById('fr1flightemail'+element).value;
        document.getElementById('frflightdess').value = document.getElementById('fr1flightdess'+element).value;

    }
    function showedit2(element){

        document.fr.style.visibility='visible';
        document.getElementById('frinsert').style.visibility='hidden';
        document.getElementById('frupdate').style.visibility='hidden';
        document.getElementById('frdelete').style.visibility='visible';
        document.getElementById('frflightid').disabled= true;
        document.getElementById('frflightidd').value = document.getElementById('fr1flightid'+element).value;
        document.getElementById('frflightid').value = document.getElementById('fr1flightid'+element).value;
        document.getElementById('frflightcode').value = document.getElementById('fr1flightcode'+element).value;
        document.getElementById('frflightdepar').value = document.getElementById('fr1flightdepar'+element).value;
        document.getElementById('frflightdes').value = document.getElementById('fr1flightdes'+element).value;
        document.getElementById('frflightdate').value = document.getElementById('fr1flightdate'+element).value;
        document.getElementById('frflighttime').value = document.getElementById('fr1flighttime'+element).value;
        document.getElementById('frflightweb').value = document.getElementById('fr1flightweb'+element).value;
        document.getElementById('frflightemail').value = document.getElementById('fr1flightemail'+element).value;
        document.getElementById('frflightdess').value = document.getElementById('fr1flightdess'+element).value;
    }
</script>
<pg:pager url="paging.do" maxIndexPages="10" maxPageItems="10">
    <pg:param name="action" value="pagingFlight"/>
    <form name="fr1">

        <table cellspacing="0" cellpadding="0" border="0" width="85%" align="center"><!-- Table -->
            <thead style="background-color:#C2D1D8">
                <tr>

                    <td><font size="3">FlightId</font></td>
                    <td><font size="3">FlightCode</font></td>
                    <td><font size="3">Depature</font></td>
                    <td><font size="3">Destination</font></td>
                    <td><font size="3">FlightDate</font></td>
                    <td><font size="3">FlightTime</font></td>
                    <td><font size="3">Website</font></td>
                    <td><font size="3">Email</font></td>
                    <td><font size="3">Description</font></td>
                    <td><font size="3">Actions</font></td>

                </tr>
            </thead>

            <logic:present name="list">
                <logic:iterate name="list" id="fli">

                    <pg:item>
                        <tr bgcolor="#F0F0F0">
                            <td><font size="1"><input type="text" size="4" style="background-color:#F0F0F0" name="fr1flightid<bean:write name="fli" property="flightId"/>" id="fr1flightid<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="flightId"/>" readonly/> </font></td>
                            <td><font size="1"><input type="text" size="4" style="background-color:#F0F0F0" name="fr1flightcode<bean:write name="fli" property="flightId"/>" id="fr1flightcode<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="flightCode"/>" readonly/> </font></td>
                            <td><font size="1"><input type="text" size="8" style="background-color:#F0F0F0" name="fr1flightdepar<bean:write name="fli" property="flightId"/>" id="fr1flightdepar<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="departure"/>" readonly/> </font></td>
                            <td><font size="1"><input type="text" size="8" style="background-color:#F0F0F0" name="fr1flightdes<bean:write name="fli" property="flightId"/>" id="fr1flightdes<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="destination"/>" readonly/> </font></td>
                            <td><font size="1"><input type="text" size="8" style="background-color:#F0F0F0" name="fr1flightdate<bean:write name="fli" property="flightId"/>" id="fr1flightdate<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="flightDate"/>"readonly/> </font></td>
                            <td><font size="1"><input type="text" size="4" style="background-color:#F0F0F0" name="fr1flighttime<bean:write name="fli" property="flightId"/>" id="fr1flighttime<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="flightTime"/>"readonly/> </font></td>
                            <td><font size="1"><input type="text" size="4" style="background-color:#F0F0F0" name="fr1flightweb<bean:write name="fli" property="flightId"/>" id="fr1flightweb<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="webSite"/>"readonly/> </font></td>
                            <td><font size="1"><input type="text" size="4" style="background-color:#F0F0F0" name="fr1flightemail<bean:write name="fli" property="flightId"/>" id="fr1flightemail<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="email"/>"readonly/> </font></td>
                            <td><font size="1"><input type="text" size="4" style="background-color:#F0F0F0" name="fr1flightdess<bean:write name="fli" property="flightId"/>" id="fr1flightdess<bean:write name="fli" property="flightId"/>" value="<bean:write name="fli" property="description"/>"readonly/> </font></td>

                            <td>
                                <logic:present name="listFunction">
                                    <logic:iterate name="listFunction" id="listF">
                                        <logic:equal name="listF" property="functionId" value="13">
                                            <img title="Add" src="admin/img/action_add.png" onclick="show();" style="cursor:pointer">
                                        </logic:equal>
                                        <logic:equal name="listF" property="functionId" value="14">
                                            <img title="Edit" src="admin/img/action_remove.png" onclick="showedit1('<bean:write name="fli" property="flightId"/>');" style="cursor:pointer">
                                        </logic:equal>
                                        <logic:equal name="listF" property="functionId" value="15">
                                            <img title="Delete" src="admin/img/action_delete.png" onclick="showedit2('<bean:write name="fli" property="flightId"/>')" style="cursor:pointer">
                                        </logic:equal>
                                    </logic:iterate>
                                </logic:present>
                            </td>
                        </tr>
                    </pg:item>

                </logic:iterate>
            </logic:present>


            <tr bgcolor="#C2D1D8">


                <td colspan="11" bgcolor="#C2D1D8"> <font color="#C2D1D8">ffff</font></td>
            </tr>

            <td colspan="11" bgcolor="#C2D1D8"> <font color="#C2D1D8">
                    <pg:index>
                        <pg:prev><a href="<%= pageUrl%>"><font color="#0D6AC1">[&lt;&lt;Prev]</font></a></pg:prev>
                        <pg:pages><a href="<%= pageUrl%>"><%= pageNumber%>&nbsp;&nbsp;</a></pg:pages>
                        <pg:next ><a href="<%= pageUrl%>"><font color="#0D6AC1">[Next&gt;&gt;]</font></a></pg:next>
                    </pg:index>

                </font></td>
            </tr>


        </table>

    </form>

</pg:pager>
<form name="fr" style="visibility:hidden" action="Adminflight.do" method="get">
    <table class="tablemain" border="0">
        <tr >
            <th height="32" colspan="3" scope="col">Manager Flight </th>
        </tr>
        <tr>
            <td width="253" height="32"><div align="right">FlightId : </div></td>
            <td width="510">
                <input type="text" name="frflightid" id="frflightid" />
                <input type="hidden" name="frflightidd" id="frflightidd" />
            </td>
        </tr>
        <tr>
            <td height="39"><div align="right">FlightCode : </div></td>
            <td><input type="text" name="frflightcode" id="frflightcode"/></td>

        </tr>

        <tr>
            <td height="39"><div align="right">Departure : </div></td>
            <td><input type="text" name="frflightdepar" id="frflightdepar"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Destination : </div></td>
            <td><input type="text" name="frflightdes" id="frflightdes"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">FlightDate : </div></td>
            <td><input type="text" name="frflightdate" id="frflightdate"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">FlightTime : </div></td>
            <td><input type="text" name="frflighttime" id="frflighttime"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Website : </div></td>
            <td><input type="text" name="frflightweb" id="frflightweb"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Email : </div></td>
            <td><input type="text" name="frflightemail" id="frflightemail"/></td>

        </tr>
        <tr>
            <td height="39"><div align="right">Description : </div></td>
            <td>
                <textarea name="frflightdess" id="frflightdess" cols="100" rows="10"></textarea>
            </td>

        </tr>
        <tr>
            <td height="39" colspan="2"><div align="center">

                    <input type="submit" name="action" value="insertFlight" id="frinsert" onclick="return formValidator();"/>
                    <input type="submit" name="action" value="UpdateFlight" id="frupdate" onclick="return formValidator();" />
                    <input type="submit" name="action" value="deleteFlight" id="frdelete" />
                </div>
            </td>
        </tr>
    </table>

</form>

<script language="JavaScript">
    function checkimg(element,helperMsg){
        if(element.value == "No file chosen"){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    function emailValidator(elem, helperMsg){
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if(elem.value.match(emailExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    // If the length of the element's string is 0 then display helper message
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    // If the element's string matches the regular expression it is all numbers
    function isNumeric(elem, helperMsg){
        var numericExpression = /^[0-9]+$/;
        if(elem.value.match(numericExpression)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }

    function IsMatch(elem,helperMsg)
    {
        mystring = elem.value;
        if (mystring.match(/(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d/ ) ) {
           return true;
        }
        else
        {
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }



    function formValidator(){
        // Make quick references to our fields
        var frflightcode = document.getElementById('frflightcode');
        var frflightdepar = document.getElementById('frflightdepar');
        var frflightdes = document.getElementById('frflightdes');
        var frflightdate = document.getElementById('frflightdate');
        var frflighttime = document.getElementById('frflighttime');
        var frflightweb = document.getElementById('frflightweb');
        var frflightemail = document.getElementById('frflightemail');
        var frflightdess = document.getElementById('frflightdess');

        // Check each input in the order that it appears in the form!
        if(notEmpty(frflightcode, "Please enter Flight Code")){
            if(notEmpty(frflightdepar, "Please enter Departion")){
                if(notEmpty(frflightdes, "Please enter Destina")){
                    if(IsMatch(frflightdate, "The date format should be : mm/dd/yyyy")){
                        if(notEmpty(frflighttime, "Please enter Time")){
                            if(notEmpty(frflightweb,"Please enter Website")){
                                if(emailValidator(frflightemail, "Please Check Email")){
                                    if(notEmpty(frflightemail, "Please enter Email")){
                                        if(notEmpty(frflightdess, "Please enter Dess")){
                                            return true;
                                        }
                                    }

                                }
                            }
                            
                        }
                    }
                }
            }
        }
        return false;
    }
</script>